package siga.visao_academico;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import siga.banco.conexao;
import siga.visao.index;
import siga.visao.verErros;

/**
 *
 * @author rafaelfrasson
 */
public class GestaoMatricular_altSituacao extends javax.swing.JDialog {
    private static List LRsituacao = new ArrayList();
    public static String gm_cod_acad;
    public static String gm_cod_disciplina;
    public static String gm_cod_turma;
    public static boolean gm_finaliza=false;
    /** Creates new form GestaoMatricular_altSituacao */
    public GestaoMatricular_altSituacao(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jtfSituacao = new javax.swing.JComboBox();
        jtfMedia = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Alterando Situação do Acadêmico");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jLabel1.setText("Situação do Acadêmico");
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText("Média");
        jLabel2.setName("jLabel2"); // NOI18N

        jtfSituacao.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jtfSituacao.setName("jtfSituacao"); // NOI18N
        jtfSituacao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfSituacaoActionPerformed(evt);
            }
        });

        jtfMedia.setEditable(false);
        jtfMedia.setName("jtfMedia"); // NOI18N

        jButton1.setText("Cancelar");
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Salvar");
        jButton2.setName("jButton2"); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jtfSituacao, javax.swing.GroupLayout.PREFERRED_SIZE, 230, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jtfMedia, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(214, Short.MAX_VALUE)
                .addComponent(jButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton1)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfSituacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfMedia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(29, 29, 29)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        try {
            conexao.Query("select codigo, descricao,sigla from grade_situacao order by descricao");
            jtfSituacao.removeAllItems();
            while (conexao.rs.next()) {
                LRsituacao.add(conexao.rs.getString("codigo"));
                jtfSituacao.addItem("["+conexao.rs.getString("sigla")+"] "+conexao.rs.getString("descricao"));
            }
        } catch (SQLException ex) {
            verErros.setErro(ex.getMessage());
        }
    }//GEN-LAST:event_formWindowOpened

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        
    }//GEN-LAST:event_formWindowClosed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jtfSituacaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfSituacaoActionPerformed
        if(jtfSituacao.getSelectedIndex()==5 || jtfSituacao.getSelectedIndex()==2){
            jtfMedia.setEditable(true);
        }
    }//GEN-LAST:event_jtfSituacaoActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        if(jtfSituacao.getSelectedIndex()==5 || jtfSituacao.getSelectedIndex()==2){
            if(!jtfMedia.getText().isEmpty()){
                conexao.Inserir("update diario set dt_cancelamento=now(), cod_situacao="+LRsituacao.get(jtfSituacao.getSelectedIndex())+", pre_media=\""+jtfMedia.getText().replace(',', '.')+"\" where cod_pessoa="+gm_cod_acad+" and cod_disciplina="+gm_cod_disciplina+" and cod_emp="+index.cod_emp+" and cod_matricula=\""+gm_cod_turma+"\" ");
                JOptionPane.showMessageDialog(null, "Situação Alterada com Sucesso.","Situação",JOptionPane.INFORMATION_MESSAGE);
                gm_finaliza=true;
                dispose();
            }else{
                JOptionPane.showMessageDialog(null, "O Campo média é Obrigatório.","Alerta do Sistema",JOptionPane.ERROR_MESSAGE);
                jtfMedia.requestFocus();
            }
        }else{
            conexao.Inserir("update diario set dt_cancelamento=now(), cod_situacao="+LRsituacao.get(jtfSituacao.getSelectedIndex())+" where cod_pessoa="+gm_cod_acad+" and cod_disciplina="+gm_cod_disciplina+" and cod_emp="+index.cod_emp+" and  cod_matricula=\""+gm_cod_turma+"\" ");
            JOptionPane.showMessageDialog(null, "Situação Alterada com Sucesso.","Situação",JOptionPane.INFORMATION_MESSAGE);
            gm_finaliza=true;
            dispose();
        }
    }//GEN-LAST:event_jButton2ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField jtfMedia;
    private javax.swing.JComboBox jtfSituacao;
    // End of variables declaration//GEN-END:variables

}
